#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
    int i;
    struct Node* next;
}Node;

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    Node* head = NULL;
    Node* tail = NULL;
    for (int i = 1; i <= n; i++)
    {
        Node* node = (Node*)malloc(sizeof(Node));
        node->i = i;
        node->next = NULL;

        if (head == NULL)
        {
            head = node;
            tail = head;
        }
        else
        {
            tail->next = node;
            tail = tail->next;
        }
        if (i == n)
            node->next = head;
    }

    Node* cur = head;
    Node* prev = NULL;

    while (n > 1)
    {
        int i = 1;
        while (i < m)
        {
            prev = cur;
            cur = cur->next;
            i++;
        }
        prev->next = cur->next;
        free(cur);
        n--;
        cur = prev->next;
    }
    printf("%d\n", prev->i);
    //perror(":");
    return 0;
}
struct TreeNode 
{
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};
int sumOfLeftLeaves(struct TreeNode* root)
{
    // write code here
    if (root == NULL)
        return 0;
    struct TreeNode* left = root->left;
    int leftsum = 0;
    int rightsum = 0;
    if (left->left == NULL && left->right == NULL)
    {
        //rightsum=sumOfLeftLeaves(root->right);
        return left->val;
    }

    leftsum = sumOfLeftLeaves(root->left);
    rightsum = sumOfLeftLeaves(root->right);
    return leftsum + rightsum;
}


int main()
{

    return 0;
}